package cn.flying.cloud.system.resource.controller;

import javax.annotation.Resource;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.flying.cloud.base.common.vo.PageRequest;
import cn.flying.cloud.base.common.vo.PageResponse;
import cn.flying.cloud.base.common.vo.Rt;
import cn.flying.cloud.system.resource.entity.SysResUrl;
import cn.flying.cloud.system.resource.service.SysResUrlService;


/**
 * 资源url表 前端控制器
 *
 * @author: admin
 * @date: 2024-06-13 20:08:02
 * @version: 1.0
 */
@RestController
@RequestMapping("/system/res/url")
public class SysResUrlController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private SysResUrlService sysResUrlService;

    /**
     * 分页查询资源url表数据
     *
     * @param request
     * @return
     */
    @PostMapping("page")
    public PageResponse page(@RequestBody PageRequest<SysResUrl> request) {
        PageResponse response = sysResUrlService.getPageList(request);
        return response;
    }

    /**
     * 列表查询资源url表数据
     *
     * @param sysResUrl
     * @return
     */
    @PostMapping("list")
    public Rt<?> list(@RequestBody SysResUrl sysResUrl) {
        List<SysResUrl> list = sysResUrlService.getList(sysResUrl);
        return Rt.success(list);
    }

    /**
     * 查询资源url表详情数据
     *
     * @param sysResUrl
     * @return
     */
    @PostMapping("detail")
    public Rt<?> detail(SysResUrl sysResUrl) {
        return Rt.success(sysResUrlService.getOneObj(sysResUrl));
    }

    /**
     * 根据主键ID查询资源url表详情数据
     *
     * @param id
     * @return
     */
    @PostMapping("getById")
    public Rt<?> getById(Long id) {
        SysResUrl sysResUrl = sysResUrlService.getById(id);
        return Rt.success(sysResUrl);
    }

    /**
     * 保存资源url表数据
     *
     * @param sysResUrl
     * @return
     */
    @PostMapping("save")
    public Rt<?> save(@RequestBody SysResUrl sysResUrl) {
        if (Objects.isNull(sysResUrl.getId())) {
            // 新增
            sysResUrlService.createObj(sysResUrl);
        } else {
            // 更新
            sysResUrlService.updateObj(sysResUrl);
        }
        return Rt.success("保存成功！");
    }

    /**
     * 删除资源url表数据
     *
     * @param sysResUrl
     * @return
     */
    @PostMapping("delete")
    public Rt<?> delete(SysResUrl sysResUrl) {
        sysResUrlService.deleteObj(sysResUrl);
        return Rt.success("删除成功！");
    }
}
